/* global hov */

/**
 * Desc
 * @description Holp You Do Good But Not Evil
 * @copyright   Copyright 2014-2015 <ycchen@iwshop.cn>
 * @license     LGPL (http://www.gnu.org/licenses/lgpl.html)
 * @author      Chenyong Cai <ycchen@iwshop.cn>
 * @package     Wshop
 * @link        http://www.iwshop.cn
 */

requirejs(['jquery', 'util', 'fancyBox', 'Spinner'], function ($, util, fancyBox, Spinner) {

    var hov = $('#expcompany').val();

    if (hov !== '') {
        $('.expitem').each(function () {
            if (hov.indexOf($(this).attr('data-k')) !== -1) {
                $(this).addClass('hov');
            }
        });
    }

    $('.expitem').click(function () {
        $(this).toggleClass('hov');
    });

    $('#saveBtn').click(function () {
        hov = [];
        $('.expitem.hov').each(function () {
            hov.push($(this).attr('data-k'));
        });
        $.post('?/wSettings/updateSettings/', {
            data: [
                {
                    name: 'expcompany',
                    value: hov.join(',')
                }
            ]
        }, function (r) {
            if (r > 0) {
                util.Alert('保存成功');
            } else {
                util.Alert('保存失败', true);
            }
        });
    });

});